package cn.stylefeng.guns.modular.basic.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.basic.entity.BasicTray;
import cn.stylefeng.guns.modular.basic.model.params.BasicTrayParam;
import cn.stylefeng.guns.modular.basic.service.BasicTrayService;
import cn.stylefeng.guns.sys.modular.system.entity.User;
import cn.stylefeng.guns.sys.modular.system.service.DeptService;
import cn.stylefeng.guns.sys.modular.system.service.UserService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * 托盘表控制器
 *
 * @author hu
 * @Date 2019-06-28 16:20:44
 */
@Controller
@RequestMapping("/basicTray")
public class BasicTrayController extends BaseController {

    private String PREFIX = "/basic/basicTray";

    @Autowired
    private BasicTrayService basicTrayService;

    @Autowired
    private UserService userService;

    @Autowired
    private DeptService deptService;
    /**
     * 跳转到主页面
     *
     * @author hu
     * @Date 2019-06-28
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "/basicTray.html";
    }

    /**
     * 新增页面
     *
     * @author hu
     * @Date 2019-06-28
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/basicTray_add.html";
    }

    /**
     * 编辑页面
     *
     * @author hu
     * @Date 2019-06-28
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/basicTray_edit.html";
    }

    /**
     * 新增接口
     *
     * @author hu
     * @Date 2019-06-28
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(BasicTrayParam basicTrayParam) {
        //set 交付id
        Long DeliverId = userService.getDeliverId();
        if (DeliverId!=null) {
            basicTrayParam.setDeliverId(DeliverId);
        }
        this.basicTrayService.add(basicTrayParam);
        return ResponseData.success();
    }

    /**
     * 编辑接口
     *
     * @author hu
     * @Date 2019-06-28
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(BasicTrayParam basicTrayParam) {
        this.basicTrayService.update(basicTrayParam);
        return ResponseData.success();
    }

    /**
     * 删除接口
     *
     * @author hu
     * @Date 2019-06-28
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(BasicTrayParam basicTrayParam) {
        this.basicTrayService.delete(basicTrayParam);
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     *
     * @author hu
     * @Date 2019-06-28
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(BasicTrayParam basicTrayParam) {
        BasicTray detail = this.basicTrayService.getById(basicTrayParam.getId());
        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     *
     * @author hu
     * @Date 2019-06-28
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(BasicTrayParam basicTrayParam,String condition ) {
    	User user = userService.getcurrentUser();
    	basicTrayParam.setDeliverId(user.getDeliverId());
    	basicTrayParam.setDeptId(user.getDeptId());
        return this.basicTrayService.findPageBySpec(basicTrayParam,condition,user.getOperateId());
    }

}


